import request from '@/utils/request'

// 获取新的商品信息
export const getStockAPI = (skuId) => {
  return request({
    url: `/goods/stock/${skuId}`
  })
}
// 合并本地购物车
// (登录后)把未登录时本地保存购物车列表提交到服务器上(合并)
// cartList: [{skuId, selected, count}, {}] 数据结构有要求
export const uploadMergeCartListAPI = (cartList) => {
  return request({
    url: '/member/cart/merge',
    method: 'POST',
    data: cartList
  })
}
// (登录后)获取-线上购物车列表数据
export const getAllCartListAPI = () => {
  return request({
    url: '/member/cart'
  })
}
// (登录后)加入购物车-单个商品
export const addCartAPI = ({ skuId, count }) => {
  return request({
    url: '/member/cart',
    method: 'POST',
    data: {
      skuId,
      count
    }
  })
}
// (登录后)删除购物车-商品(支持单个和多个)
export const delCartAPI = (idsArr) => {
  return request({
    url: '/member/cart',
    method: 'DELETE',
    data: {
      ids: idsArr
    }
    // 类型不能错, 值个数可以视情况传递
  })
}
// (登录后)更新线上购物车列表商品对象属性
export const updateCartAPI = ({ skuId, selected, count }) => {
  return request({
    url: `/member/cart/${skuId}`,
    method: 'PUT',
    data: {
      selected,
      count
    }
  })
}
// (登录后)更新线上购物车全选状态
export const updateSelectedAllCartAPI = ({ selected, ids }) => {
  return request({
    url: '/member/cart/selected',
    method: 'PUT',
    data: {
      selected,
      ids
    }
  })
}
